package com.csii.pos.ifbtoolspref;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.csii.adhoc.annotation.OperationLog;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.csii.adhoc.util.ConvertUtils;
import com.csii.adhoc.controller.BaseController;
import com.csii.pos.ifbtoolspref.service.IIfbToolsPrefService;
import com.csii.pos.ifbtoolspref.vo.IfbToolsPrefVO;
import com.csii.result.APIResult;
import com.csii.result.PageVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;



 /**
 * @Description: 投融资工具优先级
 * @Author: power-stdio
 * @Date:   2021-07-06
 * @Version: V1.0
 */

@RestController
@RequestMapping("/ifbToolsPref")
@Slf4j
public class IfbToolsPrefController extends BaseController<IfbToolsPref, IIfbToolsPrefService> {
	@Autowired
	private IIfbToolsPrefService ifbToolsPrefService;

	/**
	 * 分页列表查询
	 *
	 * @param ifbToolsPrefVO
	 * @return
	 */
	@OperationLog(value = "投融资工具优先级-分页列表查询")
	@PostMapping(value = "/queryPageList")
	public APIResult<?> queryPageList(@RequestBody IfbToolsPrefVO ifbToolsPrefVO) {
		Page<IfbToolsPref> page = new Page<IfbToolsPref>(ifbToolsPrefVO.getPageNo(), ifbToolsPrefVO.getPageSize());
		IPage<IfbToolsPrefVO> pageList = ifbToolsPrefService.page(page,ifbToolsPrefVO);
		PageVo pageVoFromIPage = PageVo.getPageVoFromIPage(pageList);
		return APIResult.successResult(pageVoFromIPage);
	}

	/**
	 *   添加
	 *
	 * @param ifbToolsPrefVO
	 * @return
	 */
	@OperationLog(value = "投融资工具优先级-添加")
	@PostMapping(value = "/addIfbToolsPref")
	public APIResult<?> addIfbToolsPref(@RequestBody IfbToolsPrefVO ifbToolsPrefVO) {
		int add = ifbToolsPrefService.addIfbToolsPref(ifbToolsPrefVO);
		if (add<=0){
			return APIResult.failResult(null,"添加失败");
		}
		return APIResult.successResult("添加成功！");
	}

	/**
	 *  编辑
	 *
	 * @param ifbToolsPrefVO
	 * @return
	 */
	@OperationLog(value = "投融资工具优先级-编辑")
	@PostMapping(value = "/editIfbToolsPref")
	public APIResult<?> edit(@RequestBody IfbToolsPrefVO ifbToolsPrefVO) {
		int upd = ifbToolsPrefService.updateIfbToolsPref(ifbToolsPrefVO);
		if (upd <= 0){
			return APIResult.failResult(null,"修改失败");
		}
		return APIResult.successResult("修改成功！");
	}

	 /**
	  * @description:  输入框查询是提示接口
	  * @param: hintVo
	  * @return:  模糊查询list
	  * @author liuzhonghua
	  * @date:
	  */
	 @RequestMapping("queryHint")
	 public APIResult<?> queryHint(@RequestBody IfbToolsPrefVO ifbToolsPrefVO) {
		 QueryWrapper<IfbToolsPref> queryWrapper = new QueryWrapper<>();
		 queryWrapper.select("DISTINCT IFB_TOOL_TYPE");
		 if (!StringUtils.isEmpty(ifbToolsPrefVO.getIfbToolType())) {
			 queryWrapper.like("IFB_TOOL_TYPE", ifbToolsPrefVO.getIfbToolType());
		 }
		 List<IfbToolsPref> list = ifbToolsPrefService.list(queryWrapper);
		 return APIResult.successResult(list);
	 }

	/**
	 *   通过id删除
	 * @param
	 * @return
	 */
	@OperationLog(value = "投融资工具优先级-通过ifbToolType删除")
	@PostMapping(value = "/deleteIfbToolsPref")
	public APIResult<?> delete(@RequestBody Map<String,String> map) {
		int del = ifbToolsPrefService.deleteIfbToolsPref(map.get("ifbToolType"),map.get("type"));
		if (del <= 0){
			return APIResult.failResult(null,"删除失败");
		}
		return APIResult.successResult("删除成功！");
	}


	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@OperationLog(value = "投融资工具优先级-批量删除")
	@PostMapping(value = "/deleteBatch")
	public APIResult<?> deleteBatch(@RequestBody List<IfbToolsPrefVO> ids) {
		this.ifbToolsPrefService.removeByIds(ids.stream().map(IfbToolsPrefVO::getIfbToolType).collect(Collectors.toList()));
		return APIResult.successResult("批量删除成功!");
	}

	/**
	 * 通过id查询
	 *
	 * @param
	 * @return
	 */
	@OperationLog(value = "投融资工具优先级-通过id查询")
	@PostMapping(value = "/queryById")
	public APIResult<?> queryById(@RequestParam(name="ifbToolType",required=true) String ifbToolType) {
		IfbToolsPref ifbToolsPref = ifbToolsPrefService.getById(ifbToolType);
		if(ifbToolsPref==null) {
			return APIResult.failResult(null, "未找到对应数据");
		}
		IfbToolsPrefVO ifbToolsPrefVO  = ConvertUtils.convert(IfbToolsPrefVO.class,ifbToolsPref);
		return APIResult.successResult(ifbToolsPrefVO);
	}

//    /**
//    * 导出excel
//    *
//    * @param
//    * @param ifbToolsPrefVO
//    */
//    @RequestMapping(value = "/exportXls")
//    public ModelAndView exportXls(HttpServletResponse response, IfbToolsPrefVO ifbToolsPrefVO) {
//        IfbToolsPref ifbToolsPref  = ConvertUtils.convert(IfbToolsPref.class,ifbToolsPrefVO);
//        return super.exportXls( ifbToolsPref, IfbToolsPref.class, "投融资工具优先级");
//    }
//
//    /**
//      * 通过excel导入数据
//    *
//    * @param
//    * @param
//    * @return
//    */
//    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
//    public APIResult<?> importExcel(@RequestParam("file") MultipartFile file) throws Exception {
//        return APIResult.successResult(super.importExcel(file, IfbToolsPref.class));
//    }
}
